#include "can_example1.h"
#include "../system/system.h"
#include "../../SpecialFunctions/UartScreen.h"
#include "../gpio/gpio.h"

uCAN1_MSG sendCanMsg1;
uCAN1_MSG sendCanMsg2;
uCAN1_MSG sendCanMsg3;
uCAN1_MSG sendCanMsg4;
uCAN1_MSG sendCanMsg5;


void can_data_initial()
{
    sendCanMsg1.frame.id = 0x42D3D5;
    sendCanMsg1.frame.idType = CAN1_FRAME_EXT;
    sendCanMsg1.frame.msgtype = CAN1_MSG_DATA;
    sendCanMsg1.frame.dlc = 8;
    sendCanMsg1.frame.data0 = 0x22;
    sendCanMsg1.frame.data1 = 0x01;
    sendCanMsg1.frame.data2 = 0x02;
    sendCanMsg1.frame.data3 = 0x03;
    sendCanMsg1.frame.data4 = 0x04;
    sendCanMsg1.frame.data5 = 0x05;
    sendCanMsg1.frame.data6 = 0x06;
    sendCanMsg1.frame.data7 = 0x07;
    
    sendCanMsg2.frame.id = 0x43D3D5;
    sendCanMsg2.frame.idType = CAN1_FRAME_EXT;
    sendCanMsg2.frame.msgtype = CAN1_MSG_DATA;
    sendCanMsg2.frame.dlc = 8;
    sendCanMsg2.frame.data0 = 0x33;
    sendCanMsg2.frame.data1 = 0x01;
    sendCanMsg2.frame.data2 = 0x02;
    sendCanMsg2.frame.data3 = 0x03;
    sendCanMsg2.frame.data4 = 0x04;
    sendCanMsg2.frame.data5 = 0x05;
    sendCanMsg2.frame.data6 = 0x06;
    sendCanMsg2.frame.data7 = 0x07;
    
    sendCanMsg3.frame.id = 0x44D3D5;
    sendCanMsg3.frame.idType = CAN1_FRAME_EXT;
    sendCanMsg3.frame.msgtype = CAN1_MSG_DATA;
    sendCanMsg3.frame.dlc = 8;
    sendCanMsg3.frame.data0 = 0x44;
    sendCanMsg3.frame.data1 = 0x01;
    sendCanMsg3.frame.data2 = 0x02;
    sendCanMsg3.frame.data3 = 0x03;
    sendCanMsg3.frame.data4 = 0x04;
    sendCanMsg3.frame.data5 = 0x05;
    sendCanMsg3.frame.data6 = 0x06;
    sendCanMsg3.frame.data7 = 0x07;
    
    sendCanMsg4.frame.id = 0x45D3D5;
    sendCanMsg4.frame.idType = CAN1_FRAME_EXT;
    sendCanMsg4.frame.msgtype = CAN1_MSG_DATA;
    sendCanMsg4.frame.dlc = 8;
    sendCanMsg4.frame.data0 = 0x55;
    sendCanMsg4.frame.data1 = 0x01;
    sendCanMsg4.frame.data2 = 0x02;
    sendCanMsg4.frame.data3 = 0x03;
    sendCanMsg4.frame.data4 = 0x04;
    sendCanMsg4.frame.data5 = 0x05;
    sendCanMsg4.frame.data6 = 0x06;
    sendCanMsg4.frame.data7 = 0x07;
    
    sendCanMsg5.frame.id = 0x46D3D5;
    sendCanMsg5.frame.idType = CAN1_FRAME_EXT;
    sendCanMsg5.frame.msgtype = CAN1_MSG_DATA;
    sendCanMsg5.frame.dlc = 8;
    sendCanMsg5.frame.data0 = 0x66;
    sendCanMsg5.frame.data1 = 0x01;
    sendCanMsg5.frame.data2 = 0x02;
    sendCanMsg5.frame.data3 = 0x03;
    sendCanMsg5.frame.data4 = 0x04;
    sendCanMsg5.frame.data5 = 0x05;
    sendCanMsg5.frame.data6 = 0x06;
    sendCanMsg5.frame.data7 = 0x07;
}

void can_send_task_example(void)
{
    
    ECAN1_Transmit_g(ECAN1_PRIORITY_MEDIUM, &sendCanMsg1);
    
     
    ECAN1_Transmit_g(ECAN1_PRIORITY_MEDIUM, &sendCanMsg2);
    
    
    ECAN1_Transmit_g(ECAN1_PRIORITY_MEDIUM, &sendCanMsg3);
    
    
    ECAN1_Transmit_g(ECAN1_PRIORITY_MEDIUM, &sendCanMsg4);
    
    
    ECAN1_Transmit_g(ECAN1_PRIORITY_MEDIUM, &sendCanMsg5);
    
}

void can_receive_task_example()
{
    uCAN1_MSG receiveCanMsg;
    bool b = ECAN1_ReceiveCanMsg_g(&receiveCanMsg);

    if(!b)
        return;

    
    switch(receiveCanMsg.frame.data0)
    {
        case 0:
            sendCanMsg1.frame.data0 = receiveCanMsg.frame.data0;
            break;
        case 1:
            sendCanMsg2.frame.data0 = receiveCanMsg.frame.data0;
            break;
        case 2:
            sendCanMsg3.frame.data0 = receiveCanMsg.frame.data0;
            break;
        case 3:
            sendCanMsg4.frame.data0 = receiveCanMsg.frame.data0;
            break;
        case 4:
        default:
            sendCanMsg5.frame.data0 = receiveCanMsg.frame.data0;
            break;
    }
}

/**
 End of File
*/